<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <title></title>
        <link rel="stylesheet" href="__PUBLIC__/Home/yian/css/index.css" />
        <script type="text/javascript" src="__PUBLIC__/Home/default/js/jquery-1.5.js"></script>
        <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.3&key=0d74cc68e3a5d0f88f59a4c80a2ce247&plugin=AMap.Geocoder"></script>
        <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>

        <script type="text/javascript">
            var map, geolocation;
            //加载地图，调用浏览器定位服务
            map = new AMap.Map('container', {
                resizeEnable: true
            });
            map.plugin('AMap.Geolocation', function() {
                geolocation = new AMap.Geolocation({
                    enableHighAccuracy: true,//是否使用高精度定位，默认:true
                    timeout: 2000          //超过2秒后停止定位，默认：无穷大
                });
                map.addControl(geolocation);
                geolocation.getCurrentPosition();
                AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
                AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
            });
            
           
            //解析定位结果
            function onComplete(data) {
                regeocoder([data.position.getLng(),data.position.getLat()]);
            }
            //解析定位错误信息
            function onError(data) {
                var id = document.getElementById('id');
                $.ajax({
                    type: "POST",
                    url: "{:U('Index/upAdd')}",
                    data:{id:id.value},
                    dataType: "json"
                });
                alert('定位失败');
            }
            
            function regeocoder(lnglatXY) {  //逆地理编码
                var geocoder = new AMap.Geocoder({
                    radius: 1000,
                    extensions: "all"
                });    
                //alert(lnglatXY);
                geocoder.getAddress(lnglatXY, function(status, result) {
                    console.log(status);
                    if (status === 'complete' && result.info === 'OK') {
                        geocoder_CallBack(result);
                    }else{
                        var id = document.getElementById('id');
                        $.ajax({
                            type: "POST",
                            url: "{:U('Index/upAdd')}",
                            data:{id:id.value},
                            dataType: "json"
                        });
                        alert('地址解析失败');
                    }
                });
            }
            
            function geocoder_CallBack(data) {
                var address = data.regeocode.formattedAddress; //返回地址描述
                var id = document.getElementById('id');
                var add = document.getElementById('add');
                $.ajax({
                    type: "POST",
                    url: "{:U('Index/upAdd')}",
                    data:{add:address,id:id.value},
                    dataType: "json"
                });
                add.innerHTML = '当前扫码位置：' + address;
            }
            //alert('请允许获取地理位置，否则无法领取红包');    
            //window.onload = getCurrentPosition();  

        </script>
    </head>
    <body <if condition="($code['status'] eq 1)">id="body1"<else/>id="b_2"</if>>
    <header>
        <img src="__PUBLIC__/Home/yian/images/logo.png" alt="" />
    </header>
    <section>
        <div class="care">
            <input type="hidden" id="id" value="{$code.id}" />
            <p>
            <if condition="($code['status'] eq 1) and ($code['num'] eq 0)">{$seller.message1}
                <elseif condition="($code['num'] lt 5) and ($code['num'] gt 0)"/>亲，此产品经我公司数据分析为{$code['num']}次扫描谨慎购买。
                <else/>{$seller.message3}</if>
            </p>
            <p class="code">
                二维码编号：<span>{$code.code}</span>
            </p>
            <if condition="($code['status'] eq 1) and ($code['num'] eq 0)"><img src="__PUBLIC__/Home/yian/images/right.png" alt="" class="right"/>
                <elseif condition="($code['num'] lt 5) and ($code['num'] gt 0)"/><img src="__PUBLIC__/Home/yian/images/care.png" alt="" class="right_2"/>
                <else/><img src="__PUBLIC__/Home/yian/images/fault.png" alt="" class="right_2"/></if>
        </div>
        <div class="box"></div>
        <div class="locate">
            <if condition="$code['status'] eq 2">
                <p>
                    第一次扫码位置：{$code.add}
                </p>
            </if>
            <p>
                <span style="letter-spacing:2px;" ID="add">当前扫码位置：</span>
            </p>
        </div>
        <div class="product">
            <img src="__PUBLIC__/Home/yian/images/product.jpg" alt="" />
        </div>
        <div class="msg">
            <p>省代信息</p>
        </div>
        <div class="msg_text">
            <if condition="$areaid eq 220000">
                <p>吉林省华瑞消防设备有限公司，主营消防器材设备批发销售。</p>
                <p>地址1：位于长春市宽城区新光复路市场北二路041</p>
                <p>电&nbsp;话&nbsp;：0431-85267755/18404317755</p>
                <p>地址2：吉林市龙潭区华丹大街三角地</p>
                <p>电&nbsp;话&nbsp;：0432-67670119/15104322266</p>
                <else/>
                <p>新疆宁豫昌茂商贸有限公司</p>
                <p>地址：新疆乌鲁木齐市水磨沟区南湖安居北路121号</p>
                <p>电话：18095992733</p>
            </if>
        </div>
    </section>
    <if condition="$menu['showinhome'] eq 1">
        <include file="index:nav1" />
    </if>
</body>
</html>
